package cn.detu.coolshark.controller;

import cn.detu.coolshark.entity.Category;
import cn.detu.coolshark.mapper.CategoryMapper;
import cn.detu.coolshark.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CategoryController {

    @Autowired(required = false)
    CategoryMapper mapper;
    @Autowired(required = false)
    ProductMapper productMapper;

    @RequestMapping("/category/select")
    public List<Category> select(){
        return mapper.select();
    }

    @RequestMapping("/category/insert")
    public void insert(Category category){
        mapper.insert(category);
    }

    @RequestMapping("/category/insertByName")
    public void insertByName(String name){
        mapper.insertByName(name);
    }
    @RequestMapping("/category/delete")
    public void delete(int id){
        productMapper.deleteByCid(id);
        mapper.delectById(id);
    }
}
